#coding:utf8
from mpp_sub import *
from bk_jump import *
def can_auto_to_man(ct,todo):
    whon = cfg.twh_has_left and not cfg.twh_has_right and cfg.twh_on and cfg.twh_has_wheel and \
    cfg.twh_start_state

    if is_jump_base():
        return False
        
    if cfg.mouse_track_on and ct-cfg.right_mouse_time>0.2 and ct-cfg.left_mouse_time>0.2:
        if todo:
            left_wheel_on_track_over()
            if cfg.right_mouse_time-cfg.first_right_time<0.2:
                cfg.acc_no_reset=True
            cfg.mouse_track_on=False
            cfg.keep_qu_cancle=True
            dis = cal_dis(get_cur_pos(),cfg.track_start_pos)
            time_d = ct-cfg.mouse_track_start_time
            dt = cfg.right_mouse_time-cfg.left_mouse_time

            bi = 100
            isx = abs(cfg.track_dx[2])>abs(cfg.track_dx[3])
            tox = (abs(cfg.track_dx[0]) + abs(cfg.track_dx[2]) )
            if not isx:
                tox = (abs(cfg.track_dx[1]) + abs(cfg.track_dx[3]) )
            if dis>0:
                bi = tox/dis
            fen = cfg.track_dx[0]*cfg.track_dx[2]<0 and abs(cfg.track_dx[0])>20 and abs(cfg.track_dx[2])>20
            if not isx:
                fen = cfg.track_dx[1]*cfg.track_dx[3]<0 and abs(cfg.track_dx[1])>20 and abs(cfg.track_dx[3])>20
            
            if dis<shuang_to_kuai_limit and bi>2.5 and cfg.track_has_shuang and not is_acc_up() and \
                fen and dt<0.2 and cfg.track_dx_abs<5*shuang_to_kuai_limit and  time_d<0.5:
                enter_ge_mode(1)
                cfg.show_ff=True                
            
            # print('track over',cfg.track_dx,dis,cfg.track_dx_abs,dt,time_d)   
                        
            if cfg.jump_state==0 and cfg.jump_kuai==0 and not cfg.can_set_acc and not is_no_move():
                cfg.can_set_acc=True
                set_acc()
        if cfg.jump_state==0 and not cfg.mouse_track_has_right and not is_acc_up() and \
            cfg.jump_to>2 and not whon:
            if not todo:
                return True
            jump_state_chg(1)
            cfg.can_break=True
            cfg.jump_from_click=False
            return True
        return False        
    
def check_track_over(ct):
    if cfg.mouse_track_on and ct-cfg.mouse_track_start_time>0.13 and \
        cfg.jump_state==0 and not cfg.can_set_acc and cfg.jump_kuai==0:
        if not is_no_move():
            cfg.can_set_acc=True
            set_acc()
    can_auto_to_man(ct,True)

def moveF():    
    while True:
        time.sleep(0.01)    
        period_call()
        ct = time.time()
        if not is_jump_base() and ct-cfg.left_mouse_time>0.2 and ct-cfg.right_mouse_time<0.1 and \
        cfg.jump_state==0:
            if cfg.mouse_speed>1000 and not cfg.acc_no_reset and cfg.acc_add>liang_conf[0]:
                cfg.jump_kuai=3
            if cfg.mouse_speed<1000 and cfg.jump_kuai==3:
                set_kuai(0)

        if cfg.show_ff and ct-cfg.right_mouse_time>jump_qu_interval and ct-cfg.left_mouse_time>jump_qu_interval and \
        cfg.right_mouse_time!=0 and cfg.left_mouse_time!=0 and cfg.jump_kuai==0:
            cfg.show_ff=False
            acc_total()
        tt = reset_acc_interval        
        if ct-cfg.right_mouse_time>tt and ct-cfg.left_mouse_time>tt and \
        cfg.can_set_acc and not cfg.acc_no_reset:
            cfg.can_set_acc=False
            cal_sup_ran()
        if cfg.right_hou_pressed and not is_jump_base():
            if  ct-cfg.right_hou_time>0.2 and not cfg.right_hou_has_other:
                deal_hou()

        if cfg.mouse_track2_on and ct-cfg.right_mouse_time>0.1 and ct-cfg.left_mouse_time>0.1:
            cfg.mouse_track2_on=False
            clear_max_speed()
            s1 = (abs(cfg.jump_dx[0])>=jump_len or abs(cfg.jump_dx[1])>=jump_len )
            s2 = (abs(cfg.jump_dx_o[0])>=jump_len or abs(cfg.jump_dx_o[1])>=jump_len )            
            if cfg.jump_state==0 and cfg.jump_kuai==0 and (s1 or s2):
                print('into bk',cfg.jump_dx,cfg.jump_dx_o)
                dd = abs(cfg.track_dx[0]+cfg.track_dx[2]) +abs(cfg.track_dx[1]+cfg.track_dx[3])
                xx = random.randint(0,5)<=1 and (dd>shuangJumpLimit or  cfg.track_dx_abs>shuangJumpLimit_abs)
                if s1:
                    if abs(cfg.jump_dx[0])>=jump_len and abs(cfg.jump_dx[1])>=jump_len:
                        cfg.jump_dx[0] = cfg.jump_dx[0]//2
                        cfg.jump_dx[1] = cfg.jump_dx[1]//2
                    if xx:
                        cfg.jump_dx[0],cfg.jump_dx[1],isJ=do_step_jump(get_cur_pos(),cfg.jump_dx[0],cfg.jump_dx[1],jump_len)
                else:
                    if abs(cfg.jump_dx_o[0])>=jump_len and abs(cfg.jump_dx_o[1])>=jump_len:
                        cfg.jump_dx_o[0] = cfg.jump_dx_o[0]//2
                        cfg.jump_dx_o[1] = cfg.jump_dx_o[1]//2
                    if xx:
                        cfg.jump_dx[0],cfg.jump_dx[1],isJ=do_step_jump(get_cur_pos(),cfg.jump_dx_o[0],cfg.jump_dx_o[1],jump_len)
                if xx:
                    print('bk jump',isJ,ct)
                cfg.jump_dx = [0,0]
                cfg.jump_dx_o = [0,0]
        check_track_over(ct)        
        period_job()

def set_mouse_time(h,t):     
    if h in cfg.left_mouse:
        cfg.left_mouse_time = t
    if h in cfg.right_mouse:
        cfg.right_mouse_time = t

def pro_get(q):
    from keyr import on_press,on_release
    from mm import on_right
    while True:
        aa = q.get()        
        ty, a, x, y, t = aa
        if ty=='mid' and a in cfg.left_mouse:
            cfg.left_mid_time = time.time()
            cfg.to_co+=1
            cfg.mid_co=cfg.to_co
            continue
        if ty=='right' and a in cfg.left_mouse:
            cfg.left_right_time = time.time()
            cfg.to_co+=1
            cfg.x2_co=cfg.to_co
            continue

        if ty=='left' and a in cfg.left_mouse and a==cfg.left_mouse[0]:
            cfg.left_left_time = time.time()
            continue

        if ty=='t1up': #后退松开
            if a in cfg.left_mouse:
                on_right(False)
            elif a != cfg.right_mouse[0] and str(a)!='None':
                on_release(scroll_str+'_lock')
            else:             
                if not cfg.right_hou_has_other:
                    print('hout',time.time()-cfg.right_hou_time)
                    hou_click()
                cfg.right_hou_pressed=False
            continue
        if ty=='t1down': #后退按下
            if a in cfg.left_mouse:                
                on_right(True)
            elif a != cfg.right_mouse[0] and str(a)!='None':
                on_press(scroll_str+'_lock')
            else:
                cfg.right_hou_pressed=True
                cfg.right_hou_has_other=False 
                cfg.right_hou_dx=0        
                cfg.right_hou_time=time.time()       
            continue

        if ty=='t2up':  #前进松开
            if a in cfg.left_mouse:
                on_click2(0,0,'x2',False,True)
            else:
                print('qian release')
                cfg.qian_pressed=False
                if not cfg.qian_other:
                    acc_down(True)

            continue
        if ty=='t2down': #前进按下
            if a in cfg.left_mouse:
                on_click2(0,0,'x2',True,True)
            else:
                print('qian press')
                cfg.qian_pressed=True
                cfg.qian_other=False
                if not is_acc_up():
                    qian_click()
            continue

        if ty == 'w':
            if str(a) == 'None':
                continue            
            if a in cfg.left_mouse:
                cfg.left_sc_time=time.time()
            if a in cfg.right_mouse:
                cfg.last_move_is_right_solo=False
                if cfg.min_ge!=0 and is_no_move():
                    if cfg.min_ge==3 and kuai_ge_chg:
                        cfg.getokuai=100
                    else:
                        enter_ge_mode(1)
                        cfg.getokuai=False                
                else:
                    if cfg.jump_state!=0:
                        jump_state_chg(0)
                    acc_down(True)
                    set_kuai(0)

            if not cfg.w2showing:
                if cfg.x2_pressed:
                    cfg.x2_pressed_then_other = True
                    dotdot()
                if cfg.middle_pressed:
                    cfg.middle_pressed_other = True
                    dotdot()
                if cfg.ctrl2_job:
                    cfg.ctrl2_other = True
                    dotdot()
               
                if a in cfg.right_mouse:
                    continue
                if a in cfg.left_mouse:
                    deal_left_wheel(x)
                    
                    continue                             
                continue            
            deal_wheel(a,x)               
            continue
        if ty!='m':
            continue     
        deal_moving(a, x, y, t)

def left_wheel_ini():
    if cfg.twh_on:
        return
    cfg.twh_on=True
    cfg.twh_start_state=False
    cfg.twh_dx=0
    cfg.twh_start_time=time.time()
    if is_jump_base():        
        return
    if cfg.jump_state!=0:
        return
    if cfg.jump_kuai!=0:
        return
    if is_acc_up():
        return
    cfg.twh_start_state=True

def do_twh_cl():
    twh_clear()
    set_kuai(0)
    cfg.twh_can_reset=False
    
def deal_left_wheel(x):
    cfg.mv_after_wheel=0
    tt=1
    if x<0:
        tt=-1
    if cfg.twh_has_turn*tt<0 and time.time()-cfg.twh_left_time>0.2:
        do_twh_cl()
        return
    if cfg.jump_kuai!=0 and cfg.twh_has_turn==0 and time.time()-cfg.twh_left_time>0.2:
        cfg.twh_has_turn=-tt
        do_twh_cl()
        return
    
    left_wheel_ini()
    cfg.twh_has_wheel=True
    cfg.twh_last_is_left= x>0
    if not cfg.twh_start_state:
        return
    if cfg.twh_has_left and not cfg.twh_has_right :
        jump_state_chg(0)
        acc_total()
        acc_up()
        return
    if cfg.twh_has_left and  cfg.twh_has_right :    
        deal_moving(a,0,0,time.time())
        cfg.track_has_wheel=True
def check_left_wheel(a,x,y,t):
    check_left_wheel_in(a,x,y,t)
    if a in cfg.right_mouse and cfg.jump_kuai==0 and cfg.twh_can_reset:
        cfg.twh_has_turn=0

def twh_kuai():
    if cfg.jump_kuai==0:
        cfg.jump_kuai=2
        if cfg.twh_last_is_left:
            cfg.twh_has_turn=1
        else:
            cfg.twh_has_turn=-1
twh_dx_l = 10000
twh_time_d=5

def twh_in_kuai(t):
    if not cfg.twh_has_wheel or not cfg.twh_start_state:
        return False
    if cfg.twh_has_left and cfg.twh_has_right and t-cfg.twh_left_time<0.2 and \
         t-cfg.twh_start_time<twh_time_d:    
        if cfg.twh_dx<twh_dx_l:
            if cfg.jump_kuai==2:
                cfg.jump_kuai=1
            return True
    return False

def check_left_wheel_in(a,x,y,t):
    cfg.mv_after_wheel += abs(x)+abs(y)
    if x==0 and y==0:
        return
    left_wheel_ini()
    cfg.twh_dx += abs(x)+abs(y)
    if a in cfg.left_mouse:
        cfg.twh_has_left=True
        cfg.twh_has_turn=0
        if t-cfg.twh_left_time>0.2:
            if cfg.jump_kuai==2:
                set_kuai(0)
            cfg.jump_kuai=0
        cfg.twh_left_time=t

    else:
        cfg.twh_has_right=True
        cfg.twh_right_time=t
    if not cfg.twh_has_wheel or not cfg.twh_start_state:
        return
    if cfg.twh_has_left and cfg.twh_has_right:
        if a in cfg.left_mouse and t-cfg.twh_right_time<0.2:
            return True
        if cfg.twh_dx<twh_dx_l and a in cfg.right_mouse and t-cfg.twh_start_time<twh_time_d:
            twh_kuai()
            # print('tk',cfg.twh_dx,t-cfg.twh_start_time)
        return
    
    if cfg.twh_has_left:
        acc_up()
        return
    twh_kuai()    

def left_wheel_on_track_over():
    cfg.twh_can_reset=True
    if cfg.jump_kuai==0 and not is_acc_up():
        cfg.twh_has_turn=0
    if cfg.twh_has_left or cfg.twh_has_right:
        twh_clear()

def deal_moving(a, x, y, t):
    from mm import ini_suo
    add_mouse(a)
    if a in cfg.left_mouse and not cfg.tt_has_left and cfg.tt_co>0:
        cfg.tt_has_left=True
        cfg.tt_co= min(right_jump_thre-1,cfg.tt_co-1)
        print('left co',cfg.tt_co)
    if a not in cfg.left_mouse and a not in cfg.right_mouse:
        return
    aa = (a, x, y, t,cfg.w2showing)
    mouse_input_q.put(aa)          
    t = time.time()        
    
    if a in cfg.right_mouse:
        pm.scroll_re_dx += abs(x)+abs(y)
    if pm.scroll_re_dx<5 and t-pm.scroll_re_time<0.05 and a in cfg.right_mouse:
        return
    if pm.scroll_pressed and is_acc_up() and a in cfg.right_mouse:
        return
    
    if check_left_wheel(a,x,y,t):
        x=0
        y=0
    if a in cfg.right_mouse and a != cfg.right_mouse[0]:
        cfg.can_set_acc=True
        cfg.acc_no_reset=True
    
    if cfg.keep_qu_cancle and a in cfg.right_mouse:
        cfg.keep_qu=False
    cfg.show_ff=False
   
    if a in cfg.right_mouse:
        cfg.left_jump =False
        cfg.jump_add=0
    
    if cfg.an_mode and a in cfg.left_mouse:
        acc_up()
        cfg.ori_kuai=cfg.jump_kuai
    cfg.an_mode=False
    if cfg.min_ge!=0:
        cfg.acc_no_reset=True
    if cfg.g_is_acc and cfg.can_set_acc and not cfg.acc_no_reset and cfg.jump_kuai==0 and \
        cfg.jump_state==0  and a in cfg.left_mouse:
        if cfg.min_ge!=0:
            cfg.can_set_acc=True
    if a in cfg.left_mouse:
        cfg.acc_no_reset=True
    if cfg.min_ge!=0 and not cfg.w2showing and a in cfg.left_mouse and not cfg.no_left_move:
        ori = cfg.min_ge
        ttk = cfg.getokuai
        fm = cfg.eg_from_mid
        clear(True)
        if ori==1 and not ttk:
            jump_state_to_man()
            return
        if ori==1 and fm:
            acc_up()
            cfg.ori_kuai=1
        else:
            acc_up()
            cfg.ori_kuai=0
            if ori==1 and not fm:
                cfg.ori_kuai=0

    if not kuai_ge_chg:
        if cfg.min_ge==1 and not cfg.w2showing and a in cfg.right_mouse and cfg.getokuai:
            fm = cfg.eg_from_mid
            clear(True)
            kuai_into_2()
            if not fm:
                cfg.jump_kuai=1
    else:
        fm = cfg.eg_from_mid
        if cfg.min_ge==1 and cfg.eg_from_mid and not cfg.w2showing and a in cfg.right_mouse and cfg.getokuai:
            enter_ge_mode(3)
            cfg.getokuai=100
            return deal_moving(a, x, y, t)
        if cfg.min_ge==1 and not cfg.w2showing and a in cfg.right_mouse and cfg.getokuai:
            clear(True)
            kuai_into_2()
            # cfg.jump_kuai=1
        if cfg.min_ge==3 and cfg.getokuai!=100:
            clear(True)
            kuai_into_2()

    ps = pm.scroll_pressed or pm.enter_pressed or cfg.qian_pressed or pm.add_pressed or cfg.x2_pressed
    if pm.scroll_pressed and cfg.jump_state!=0:
        jump_state_chg(0)
    # if pm.scroll_pressed and a in cfg.right_mouse and (x!=0 or y!=0):
    #     cfg.jump_kuai=1
        # pm.scroll_other=True
    if is_acc_up() and a in cfg.right_mouse and not ps and (abs(x)>0 or abs(y)>0):
        print('mv',cfg.mv_after_wheel)
        acc_down(True)
        if cfg.mv_after_wheel<50 and cfg.ori_kuai==0:
            cfg.jump_kuai=2
        else:        
            jump_state_to_man()
            cfg.is_after_man=True
            cfg.keep_qu=True
            cfg.keep_qu_dx=0
            cfg.keep_qu_cancle=False

    if cfg.x2_pressed and not cfg.is_suo and not cfg.x2_pressed_then_other and not cfg.w2showing and \
        a in cfg.right_mouse:
        cfg.x2_pressed_then_other = True
        if cfg.mouse_tip_no_show and cfg.x2_type==0:
            pass
        else:
            print('x2 ini suo',cfg.x2_type)
            ini_suo()

    if ps and not is_jump_base() and  a in cfg.left_mouse and cfg.jump_state==0:
        acc_up()
        if pm.scroll_pressed:
            cfg.ori_kuai=0


    if a in cfg.left_mouse and (ps or cfg.acc_speed == g_mouse_speed[2]) and \
        cfg.right_mouse and not is_jump_base() and cfg.jump_state==0:
        cfg.qian_other=True
        cfg.x2_pressed_then_other=True
        pm.scroll_other=True
        pm.enter_other=True
        pm.add_other=True
        deal_moving(cfg.right_mouse[0],0,0,t)
        ttg=3
        if cfg.ori_kuai==1:
            ttg=2.4
        x *=ttg
        y *=ttg
        
    if a in cfg.right_mouse:
        if a==cfg.right_mouse[0]:
            cfg.last_is_sec_right=False
        else:
            cfg.last_is_sec_right=True

    clear_sign()
    cpos = get_cur_pos()    
    mv_call(a,t,cpos,x,y)
    moving_other(a,cpos,x,y)

    if cfg.right_hou_pressed and not is_jump_base():
        cfg.right_hou_dx+=abs(x)+abs(y)
        if cfg.right_hou_dx>50 or t-cfg.right_hou_time>0.2:
            if not cfg.right_hou_has_other:
                deal_hou()

    if a not in cfg.left_mouse and cfg.jump_state==0:
        cfg.jump_to=0
    if a in cfg.left_mouse and cfg.jump_state==1:
        cfg.jump_to=0
    
    if not cfg.mouse_track_on:
        clear_max_speed(True)
        cfg.mouse_track_on=True
        cfg.mouse_track_start_time=t
        cfg.mouse_track_has_right=False      
        cfg.track_dx=[0,0,0,0]
        cfg.track_dx_abs=0
        cfg.track_has_shuang=False
        cfg.track_start_pos=get_cur_pos()        

    if not cfg.mouse_track2_on:        
        clear_max_speed(True)
        cfg.mouse_track2_on=True
        cfg.mouse_track2_has_left=False        

    cfg.track_dx_abs+=abs(x)+abs(y)
    cfg.keep_qu_dx +=abs(x)+abs(y)
    if a in cfg.left_mouse:
        cfg.track_dx[0]+=x
        cfg.track_dx[1]+=y
        if cfg.jump_kuai!=0 and not twh_in_kuai(t):
            print('k0',t)
            set_kuai(0)
            cfg.jump_dx=[0,0]
            jump_state_chg(1)
            cfg.can_break=True
            cfg.jump_from_click=False
        cfg.acc_has_left=True
        cfg.first_right_time=0
        if t-cfg.right_mouse_time>0.1 and cfg.first_left_time==0:
            cfg.first_left_time=t
    else:
        cfg.track_dx[2]+=x
        cfg.track_dx[3]+=y
        cfg.mouse_track_has_right=True
        cfg.first_left_time=0
        if t-cfg.left_mouse_time>0.1 and cfg.first_right_time==0:
            cfg.first_right_time=t
    
    set_mouse_time(a,t)                     
    if not cfg.mouse_tip_no_show:                     
        deal_mouse_mode(a, x, y,t)    
    else:
        cfg.mouse_mode=-1
    
    do_logi(a, x, y,t,cpos)    

acc_add_print=0
def do_logi(a, x, y,t,cpos):
    global acc_add_print
    cal_mouse_speed(x,y,t)
    if cfg.mouse_speed>cfg.max_speed:
        cfg.max_speed = cfg.mouse_speed
    if cfg.slow_start_time==0 and cfg.mouse_speed<mouse_speed_gap[0] and cfg.max_speed>cfg.mouse_speed+2:
        cfg.slow_start_time=t
    if cfg.mouse_speed>mouse_speed_gap[0]:
        cfg.slow_start_time=0
    # print('mouse speed',cfg.mouse_speed,cfg.max_speed)
    if not is_jump_base() and cfg.jump_state==0 and cfg.jump_kuai==0 and t-cfg.left_mouse_time>0.2:
        if cfg.acc_add<liang_conf[1] and (not cfg.acc_no_reset or cfg.force_acc):
            cfg.acc_add += (abs(x)+abs(y))*(abs(x)+abs(y))
    else:
        if cfg.acc_add>0 and cfg.jump_kuai!=3:
            cfg.acc_add -= (abs(x)+abs(y))*liang_conf[2]
    if abs(acc_add_print-cfg.acc_add)>100000:
        acc_add_print=cfg.acc_add
        print('acc_add_print',acc_add_print)

    if cfg.jump_state==0 and t-cfg.left_mouse_time>left_mouse_delay  and cfg.first_right_time!=0 and \
         t-cfg.first_right_time>0.01:
        cfg.last_move_is_right_solo=True
        if  cfg.can_set_acc and cfg.jump_kuai==0:
            set_acc()
        elif  t-cfg.first_right_time>0.1 and not is_jump_base()  and cfg.jump_kuai==0:
            set_no_acc(cpos,t)
    if cfg.jump_kuai!=0:
        cfg.last_move_is_right_solo=False        
    if jump_state_sup2():
        cfg.middle_pressed_other=True
        cfg.x2_pressed_then_other=True      
        pm.enter_other=True
        deal_jump2(a, x, y,t,cpos)
    else:
        cfg.jump_dx=[0,0]
        cfg.jump_dx_o=[0,0]
    if is_jump_base():
        set_acc()

def deal_jump_step_base(x,y,dd1=None,isLeft=False):
    gg = jump_step
    if isLeft and jump_step_left!=0:
        gg = jump_step_left
    dx = int(x/gg)
    dy = int(y/gg)
    dd = lock_l_te.get(cfg.cur_screen,1)
    if dd1!=None:
        dd = dd1    
    if dx!=0 or dy!=0:
        mouse.Controller().move(dx*dd,dy*dd)
    return x- dx*gg,y-dy*gg    

def deal_jump_step(x,y,dd1=None,isLeft=False):
    sc=1
    if isLeft==-1 and dd1==jump_du[0] or  dd1==jump_du[3]:
        sc=dd1
        dd1=None
    
    elif isLeft and dd1!=None and (cfg.left_jump or (cfg.mouse_speed<qu_jump_limit and cfg.left_jump_can_chg)):        
        jlk = jump_left_kuai_gap
        if dd1==jump_du[2]:
            jlk = 1
        sc=dd1/jlk
        dd1=jlk
    else:
        cfg.jump_add=0

    cfg.jump_dx[0]+=x*sc
    cfg.jump_dx[1]+=y*sc
    ox,oy = cfg.jump_dx
    cfg.jump_dx[0],cfg.jump_dx[1] = deal_jump_step_base(cfg.jump_dx[0],cfg.jump_dx[1],dd1,isLeft)
    if ox!=cfg.jump_dx[0] or oy!=cfg.jump_dx[1]:
        cfg.jump_add += 1
        if cfg.jump_add>10 and cfg.left_jump_can_chg:            
            cfg.left_jump=True
            cfg.jump_add=0

def deal_jump2(a, x, y,t,cpos):
    isLeft = a in cfg.left_mouse
    lag0=0.2
    lag2=0.2
    if a in cfg.right_mouse:
        if t-cfg.first_right_time>0.2:
            cfg.keep_qu=False
    if cfg.middle_pressed or (cfg.x2_pressed and cfg.x2_type==0):
        cfg.jump_kuai=2
        if cfg.x2_pressed or cfg.middle_pressed:
            cfg.jump_kuai=1
    if isLeft:
        cfg.jump_left_pos=cpos
        cfg.is_after_man=False
    
    if cfg.jump_state!=0 : #慢速
        if cfg.jump_clear:
            cfg.jump_clear=False
            cfg.jump_dx=[0,0]

        if t-cfg.right_mouse_time>0.1: #左手单手
            set_no_acc(cpos,t)
            xxqu = cfg.keep_qu and cfg.keep_qu_dx<jump_qu_gap and time.time()-cfg.right_mouse_time<jump_qu_interval            
            if xxqu:
                cfg.can_break=True
                cfg.jump_from_click=False
            cfg.keep_qu=False
            cfg.man_has_left=False
            cfg.man_has_left=False
            if not cfg.can_break:
                deal_jump_step(x,y,None,True)                        
            else:       
                if cfg.last_move_is_right_solo and False:             
                    deal_jump_step(x,y,jump_du[2],True)                                            
                else:
                    deal_jump_step(x,y,jump_du[1],True)                                    
            return
        set_no_acc(cpos,t)
        if t-cfg.left_mouse_time>0.1: #右手鼠标
            cfg.man_has_left=False                        
            if cfg.is_after_man:         
                deal_jump_step(x,y,jump_du[3])         
            else:
                ff = False
                if not isLeft and a==cfg.right_mouse[0]:
                    ff=-1
                deal_jump_step(x,y,jump_du[0],ff)         
            cfg.can_break=False
            return
            
        #双手
        if isLeft:
            cfg.man_has_left=True
        else:
            cfg.man_has_right=True

        if (cfg.man_has_left and cfg.man_has_right) or \
              (cfg.can_break and isLeft and not cfg.jump_from_click):
            jump_state_chg(0)
            return
        deal_jump_step(x,y,jump_du[0],isLeft)
        return
    sc = jump_scal
    if isLeft :
        sc = jump_scal_left
        if cfg.last_is_sec_right:
            sc = jump_scal_sec
    elif a !=cfg.right_mouse[0]:
        sc = jump_scal_sec    
    jl = cfg.jump_len       
    if cfg.jump_kuai==2 :
        sc *=2
    isJ = False
    isShuang = (t-cfg.right_mouse_time<0.1 and  t-cfg.left_mouse_time<left_mouse_delay)    
    if isShuang:
        cfg.track_has_shuang=True        
        cfg.last_move_is_right_solo=False
    if  isShuang or  cfg.middle_pressed or cfg.jump_kuai!=0 or \
            (cfg.x2_pressed and cfg.x2_type==0)  or cfg.need_jump:
        cfg.can_set_acc=True
        set_acc()
        cfg.acc_no_reset=True
        cfg.mouse_track2_has_left=False
        cfg.jump_to=0    
        if not is_acc_up() and cfg.jump_kuai==0 and cfg.track_has_wheel and False:
            if not isLeft:
                cfg.jump_dx[0]+=x*sc*2
                cfg.jump_dx[1]+=y*sc  *2   
        else:
            cfg.jump_dx[0]+=x*sc
            cfg.jump_dx[1]+=y*sc
        if is_system_move(t):
            if not cfg.jump_need_2:
                print('set n2',cfg.mouse_speed)
            cfg.jump_need_2=True            
            if cfg.jump_dx[0]>jl:
                cfg.jump_dx[0]=jl+1
            if cfg.jump_dx[0]<-jl:
                cfg.jump_dx[0]=-jl-1
            if cfg.jump_dx[1]>jl:
                cfg.jump_dx[1]=jl+1
            if cfg.jump_dx[1]<-jl:
                cfg.jump_dx[1]=-jl-1
        else:
            ox,oy = cfg.jump_dx
            if cfg.jump_need_2 and abs(cfg.jump_dx[0])>=jl and abs(cfg.jump_dx[1])>=jl:
                cfg.jump_dx[0] = cfg.jump_dx[0]//2
                cfg.jump_dx[1] = cfg.jump_dx[1]//2
            if (cfg.jump_kuai==2 or (cfg.jump_kuai==100 and t-cfg.left_mouse_time>0.2) ) and \
                not (cfg.slow_start_time!=0 and t-cfg.slow_start_time>0.25):
                jl = 1
            cfg.jump_dx[0],cfg.jump_dx[1],isJ=do_step_jump(cpos,cfg.jump_dx[0],cfg.jump_dx[1],jl)      
            if cfg.jump_need_2:
                cfg.jump_dx_o = [ox,oy]                  
            if not cfg.jump_need_2 and isJ:
                cfg.jump_dx_o=[0,0]                            
            cfg.jump_need_2=False
            if isShuang and isJ and not cfg.has_gap:
                cfg.has_gap=True
                print('cfg.has_gap',t)
        if isShuang:
            cfg.need_jump_co+=1                        
            if need_jump_pro>0 and cfg.need_jump_co%need_jump_pro==0 and cfg.acc_add>liang_conf[0]:
                cfg.need_jump = True
            else:
                cfg.need_jump = False
        else:
            if isJ:
                cfg.need_jump = False
        cfg.jump_clear=True
        return
    if cfg.jump_clear:
        cfg.jump_clear=False
        cfg.jump_dx=[0,0]
        mouse.Controller().move(x,y)
    else:      
        if cfg.last_move_is_right_solo and False:             
            deal_jump_step(x,y,jump_du[2],True)                                            
        else:
            deal_jump_step(x,y,jump_du[1],True)         

    if t-cfg.right_mouse_time>0.1:        
        cfg.mouse_track2_has_left=True
        if t-cfg.right_mouse_time>lag0:
            cfg.jump_to += abs(x)+abs(y)
            if cfg.jump_to>jump_to_conf and t-cfg.first_left_time>lag2:
                jump_state_chg(1)
                cfg.can_break=True
                cfg.jump_from_click=False
        return
                    